<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        #myCanvas{
            border: 1px solid red;
        }
    </style>
</head>
<body>
    <center>
        <canvas id="myCanvas" width="400" height="400">

        </canvas>
    </center>
    
</body>
<script>
    /** @type {HTMLCanvasElement} */
    let myCanvas=document.querySelector("#myCanvas");
    let ctx=myCanvas.getContext("2d");
    //定义起始位置  
    ctx.beginPath();  
    ctx.lineWidth=10;
    ctx.lineCap="butt"
    ctx.strokeStyle="blue"
    ctx.moveTo(10,180);
    ctx.lineTo(50,180);
    ctx.lineTo(10,210);
    ctx.lineTo(50,210);    
    ctx.stroke();//执行绘图

    ctx.beginPath();
    ctx.lineCap="square"
    ctx.strokeStyle="pink"
    ctx.moveTo(10,240);
    ctx.lineTo(50,240);
    ctx.lineTo(10,280);
    ctx.lineTo(50,280);    
    ctx.stroke();//执行绘图

    ctx.beginPath();
    ctx.fillStyle="blue"
    ctx.moveTo(100,100);
    ctx.lineTo(100,300);
    ctx.lineTo(300,300);
    ctx.closePath();
    ctx.fill();
    ctx.stroke();

</script>
</html>